package com.neuedu.yyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.yyzx.config.CommonResult;
import com.neuedu.yyzx.entity.Bed;
import com.neuedu.yyzx.service.IBedService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 第7组....
 * @since 2021-04-29
 */
@RestController
@RequestMapping("/bed")
public class BedController {
    @Autowired
    IBedService bedService;

    @RequestMapping("/list")
    public CommonResult list(@RequestParam(defaultValue = "1") Integer pageNo , @RequestParam(defaultValue = "10") Integer pageSize, Bed bed){
        QueryWrapper queryWrapper = new QueryWrapper();
        if(bed!=null && StringUtils.isNotEmpty(bed.getName())){
            queryWrapper.like("name",bed.getName());
        }

        return CommonResult.success(bedService.page(new Page<>(pageNo,pageSize),queryWrapper));

    }

    @RequestMapping("/add")
    CommonResult add(Bed bed){
        return CommonResult.success(bedService.saveOrUpdate(bed));
    }

    @RequestMapping("/update")
    CommonResult update(Bed bed){
        return CommonResult.success(bedService.updateById(bed));
    }
    @RequestMapping("/getById")
    CommonResult getById(Integer id){
        return CommonResult.success(bedService.getById(id));
    }

    @RequestMapping("/del")
    CommonResult del(Integer id){
        return CommonResult.success(bedService.removeById(id));
    }



}
